<?php
function strip_rn($html) {
	$html = str_replace("\r", '', $html);
	$html = str_replace("\n", '', $html);
	return $html;
}  

function init_data_file($file_name) {
	$fd = fopen($file_name, "w");
	if (!$fd) {
		die("$file_name open error\n");
	}
	fclose($fd);
}

function write_array($file, $array) {
	$data = '';
	foreach ($array as $row) {
		$row = str_replace("\t", "", $row);
		$data .= "$row\t";
	}
	$data = trim($data, "\t");
	$data = "$data\n";
	append_data_file($file, $data);
}

function append_data_file($file_name, $str_data) {
	$fd = fopen($file_name, "a");
	if (!$fd) {
		die("$file_name open error\n");
	}
	fwrite($fd, $str_data);
	fclose($fd);
}

function get_match_groups($subject, $pattern) {
	$r = preg_match_all($pattern, $subject, $arr_matches);
	if ($r && isset($arr_matches[1])) {
		return $arr_matches[1];
	}
	return false;
}

function my_strip_tags($html) {
	return strip_tags($html, "<div><p><img><span>");
}

function array_trim(&$array) {
	foreach ($array as $k => $v) {
		$array[$k] = trim($v);
	}
}
